import { accessTypeEnum, ignoreAccessTypeEnumList } from './utils/enum'

type accessObjProps = {
  [key in accessTypeEnum]: boolean
} & {
  [key: string]: boolean
}

// 权限管理
export default function (initialState: initialStateProps) {
  let accessObj: { [key: string]: boolean } = {}

  for (const key in accessTypeEnum) {
    if (Object.prototype.hasOwnProperty.call(accessTypeEnum, key)) {
      accessObj[key] = false
    }
  }

  ignoreAccessTypeEnumList.forEach((key) => (accessObj[key] = true))

  initialState.access.forEach((item) => {
    accessObj[item] = true
  })

  // 返回权限信息
  return accessObj
}
